package com.ruoyi.web.controller.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.utils.Result;
import com.ruoyi.system.domain.SysTrainingCategory;
import com.ruoyi.system.domain.param.SysTrainingCategoryParam;
import com.ruoyi.system.domain.param.SysTrainingVideosParam;
import com.ruoyi.system.domain.vo.SysTrainingCategoryVo;
import com.ruoyi.system.domain.vo.SysTrainingVideosVo;
import com.ruoyi.system.service.ISysTrainingCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/training-category")
@AllArgsConstructor
@Api(value = "培训分类相关接口", tags = "培训分类相关接口")
public class SysTrainingCategoryController {

    private final ISysTrainingCategoryService trainingCategoryService;

    @PostMapping("/page")
    @ApiOperation(value = "分页查询培训分类",notes = "传入分页和查询的参数")
    @ApiOperationSupport(order = 1)
    public Result<List<SysTrainingCategoryVo>> page(@RequestBody SysTrainingCategoryParam param){
        if(null == param.getProjectId()){
            //throw new JGException(500,"请传项目id");
        }
        return trainingCategoryService.selectTrainingCategoryPage(param);
    }

    @PostMapping("/submit")
    @ApiOperation(value = "添加培训分类",notes = "传入需进行添加培训信息")
    @ApiOperationSupport(order = 2)
    public Result submit(@RequestBody SysTrainingCategory trainingCategory){
        if(null == trainingCategory.getProjectId()){
        }
        if(null == trainingCategory.getCreateUser()){
        }
        return trainingCategoryService.submit(trainingCategory);
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改培训分类",notes = "传入需进行修改的培训信息")
    @ApiOperationSupport(order = 3)
    public Result update(@RequestBody SysTrainingCategory trainingCategory){
        if(null == trainingCategory.getProjectId()){
        }
        if(null == trainingCategory.getUpdataUser()){
        }
        return trainingCategoryService.updateSysTrainingCategory(trainingCategory);
    }

    @GetMapping("/remove")
    @ApiOperation(value = "批量删除培训分类",notes = "传入培训分类id(多个则使用逗号隔开)")
    @ApiOperationSupport(order = 4)
    public Result remove(String ids,Long projectId){
        return trainingCategoryService.removeById(ids,projectId);
    }

    @GetMapping("/info")
    @ApiOperation(value = "通过id查询培训分类详情信息",notes = "传入培训分类id")
    @ApiOperationSupport(order = 5)
    public Result<SysTrainingCategoryVo> info(Long id,Long projectId){
        return trainingCategoryService.selectSysTrainingCategoryInfo(id,projectId);
    }


    @GetMapping("/storage")
    @ApiOperation(value = "培训分类上架/下架",notes = "传入培训分类id和上架/下架状态(0 下架，1 上架)")
    @ApiOperationSupport(order = 6)
    public Result storage(Long id,Integer state,Long projectId){
        return trainingCategoryService.updatePublishStorage(id,state,projectId);
    }

    @GetMapping("/selectAll")
    @ApiOperation(value = "培训分类列表展示",notes = "传入项目id")
    @ApiOperationSupport(order = 9)
    public Result selectAll(Long projectId){
        return trainingCategoryService.selectAllTrainingCategory(projectId);
    }

    @PostMapping("/videos")
    @ApiOperation(value = "大屏-获取视频url集合")
    public Result<IPage<SysTrainingVideosVo>> videos(@RequestBody SysTrainingVideosParam param){
        return trainingCategoryService.videos(param);
    }

    @GetMapping("/start")
    @ApiOperation(value = "启用大屏播放",notes = "启用大屏播放")
    @ApiOperationSupport(order = 4)
    public Result start(Integer id){
        return trainingCategoryService.start(id);
    }

    @GetMapping("/stop")
    @ApiOperation(value = "禁用大屏播放",notes = "禁用大屏播放")
    @ApiOperationSupport(order = 4)
    public Result stop(Integer id){
        return trainingCategoryService.stop(id);
    }

    @GetMapping("/selectPolling")
    @ApiOperation(value = "根据id查询出来第一个子节点集合",notes = "根据id查询出来第一个子节点")
    @ApiOperationSupport(order = 5)
    public Result selectPolling(@Param("id")Long id){
        return trainingCategoryService.selectPolling(id);
    }
}
